package ch04;

public class QuadraticEquation 
{
	private double solution1;
	private double solution2;
	
	private boolean equationHasSolution;
	
	public QuadraticEquation(double a, double b, double c)
	{
		double discriminant = b * b - 4 * a * c;
		
		if (discriminant >= 0)
		{
			equationHasSolution = true;
			
			double root1 = (-b + Math.sqrt(discriminant))/(2*a);
			double root2 = (-b - Math.sqrt(discriminant))/(2*a);
			
			solution1 = Math.min(root1, root2);
			solution2 = Math.max(root1, root2);
			
		} else {		
			equationHasSolution = false;
			
			solution1 = 0;
			solution2 = 0;
		} 		
	}
	
	public double getSolution1()
	{
		return solution1;
	}
	
	public double getSolution2()
	{
		return solution2;
	}
	
	public boolean hasSolution()
	{
		return equationHasSolution;
	}	
}
